package com.polaris.live.adapter

import android.graphics.Color
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.StringUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.polaris.live.common.R
import com.polaris.live.databinding.MessageHeaderTipBinding
import com.polaris.live.translation.R.string
import com.polaris.live.utils.route.RoutePath
import com.polaris.live.utils.route.Router
import com.polaris.live.utils.route.SpanClickUtils

/**
 * MessageHeadAdapter 添加头部
 * @author Created by 天晴 on 2024/1/13 14:57
 * @since 1.0.0
 **/
class MessageHeadAdapter :
    BaseQuickAdapter<String, MessageHeadAdapter.MessageHeadHolder>(com.polaris.live.R.layout.message_header_tip) {

    init {
        data.clear()
        data.add("MessageHeadAdapter")
    }

    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): MessageHeadHolder {
        return MessageHeadHolder(
            MessageHeaderTipBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun convert(holder: MessageHeadHolder, item: String) {

        val span = SpanClickUtils.with(holder.binding.tvCompleteData)
            .append(" ${StringUtils.getString(string.message_complete_data)}")
            .append(" ${StringUtils.getString(string.message_complete)}").setUnderline()
            .setClickSpan(object : ClickableSpan() {
                override fun updateDrawState(paint: TextPaint) {
                    paint.isUnderlineText = true
                    paint.bgColor = Color.TRANSPARENT
                }

                override fun onClick(widget: View) {
                    Router.instance.setPath(RoutePath.INFO_USER_ACTIVITY)
                        .navigation(widget.context)
                }
            })
            .setForegroundColor(ColorUtils.getColor(R.color.color_fe1849))
            .create()
        holder.binding.tvCompleteData.text = span
    }

    inner class MessageHeadHolder(val binding: MessageHeaderTipBinding) :
        BaseViewHolder(binding.root)
}